package com.eas.web.common.chart.line;

import java.text.MessageFormat;

import org.apache.commons.lang.StringUtils;

public class LineValueNode {

    public static final String FULL_FORMAT_PATTERN = "'{'\"value\":{0}, \"tip\":\"{1}\", \"on-click\":\"redirect(''{2}'')\"'}'";

    public static final String BASE_FORMAT_PATTERN = "'{'\"value\":{0}, \"tip\":\"{1}\"'}'";

    public String value;

    public String tip;

    public String url;

    public String getTip() {
        return tip;
    }

    public void setTip(String tip) {
        this.tip = tip;
    }

    public String getValue() {
        return value;
    }

    public void setValue(long value) {
        this.value = String.valueOf(value);
    }

    public void setValue(int value) {
        this.value = String.valueOf(value);
    }

    public void setValue(float value) {
        this.value = String.valueOf(value);
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String toString() {
        if (value != null) {
            if (tip != null)
                if (StringUtils.isNotBlank(url)) {
                    return MessageFormat.format(FULL_FORMAT_PATTERN,
                            StringUtils.trimToEmpty(value), StringUtils.trimToEmpty(tip),
                            StringUtils.trimToEmpty(url));
                } else {
                    return MessageFormat.format(BASE_FORMAT_PATTERN,
                            StringUtils.trimToEmpty(value), StringUtils.trimToEmpty(tip));
                }
            else {
                return value;
            }
        } else {
            return StringUtils.EMPTY;
        }
    }

    public String render() {
        return toString();
    }

}
